import Vue from 'vue'
import VMain from './Loading.vue'
// 返回一个 扩展实例构造器
const Constructor = Vue.extend(VMain)
// const defaultOptions = {}
const MyPlugin = {
  install: function(Vue, _globalOptions = {}) {
    const dom = new Constructor({
      el: document.createElement('div')
    })
    Vue.prototype.$loading = {
      open: function(text = '加载中...') {
        dom.text = text
        // 把 实例化的 组件添加到 body 里
        dom.open()
      },
      close: function() {
        dom.close()
      }
    }
    document.body.appendChild(dom.$el)
  }
}
if (typeof window !== 'undefined' && window.Vue) {
  window.Vue.use(MyPlugin.install)
}
export default MyPlugin
